#include <cstdio>
#include <cstring>

#define MAXN 100+5
#define INF 0x3F3F3F3F

int N, M;
int G[MAXN][MAXN];
int DIS[MAXN];
bool VIS[MAXN];
bool VISE[MAXN][MAXN];
int MAXD[MAXN][MAXN];
int PREV[MAXN];

int prim() {
    int cnt = 0;
    int ans = 0;
    memset(PREV, 0, sizeof(PREV));
    for (int i=1; i<=N; i++) {
        DIS[i] = G[1][i];
        PREV[i] = 1;
    }
    PREV[1] = 0;
    memset(VIS, 0, sizeof(VIS));
    memset(VISE, 0, sizeof(VISE));
    VIS[1] = true;
    while (cnt < N-1) {
        int minv=-1, minc=INF;
        for (int i=1; i<=N; i++) {
            if (!VIS[i] && DIS[i] < minc) {
                minc = DIS[i];
                minv = i;
            }
        }
        VIS[minv] = true;
        VISE[minv][PREV[minv]] = true;
        VISE[PREV[minv]][minv] = true;
        ans += minc;
        cnt++;
        for (int i=1; i<=N; i++) {
            if (!VIS[i] && G[minv][i] < DIS[i]) {
                DIS[i] = G[minv][i];
                PREV[i] = minv;
            }
            if (VIS[i] && i!=minv) {
                MAXD[i][minv] = minc;
                MAXD[minv][i] = minc;
            }
        }
    }
    return ans;
}

int smst(int mst) {
    int ans = INF;
    for (int i=1; i<=N; i++) {
        for (int j=1; j<=N; j++) {
            if (G[i][j] < INF && !VISE[i][j]) {
                if (mst + G[i][j] - MAXD[i][j] < ans) {
                    ans = mst + G[i][j] - MAXD[i][j];
                }
            }
        }
    }
    return ans;
}

//void print() {
//    for (int i=1; i<=N; i++) {
//        for (int j=i+1; j<=N; j++) {
//            if (VISE[i][j]) {
//                printf("%d-%d\n", i, j);
//            }
//        }
//    }
//    printf("-----------------------------\n");
//    for (int i=1; i<=N; i++) {
//        if (PREV[i] != 0) {
//            printf("%d-%d\n", PREV[i], i);
//        }
//    }
//}

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        scanf("%d%d", &N, &M);
        memset(G, 0x3F, sizeof(G));
        for (int i=0; i<M; i++) {
            int x, y, w;
            scanf("%d%d%d", &x, &y, &w);
            G[x][y] = w;
            G[y][x] = w;
        }
        int ans1 = prim();
        //printf("%d\n", ans1);
        //print();
        int ans2 = smst(ans1);
        if (ans1 == ans2) {
            printf("Not Unique!\n");
        } else {
            printf("%d\n", ans1);
        }
    }
    return 0;
}
